<?php

/**
 * 专辑内容审核AJAX
 * 
 * @copyright xinwei
 * @since 2012-03-22
 */

include_once($_SERVER["DOCUMENT_ROOT"] . "/core/inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/core/admin.inc.php");
include_once($_SERVER["DOCUMENT_ROOT"] . "/include/foodv2/inc.php");

$g_cgival = array();
$g_pro = array();
$g_show = array();


function check_cgi_pro()
{
	global $g_cgival, $g_pro, $g_show;
	
	//专辑ID
	cgi::get($g_cgival["album_id"], "album_id", "");
	$g_cgival["album_id"] = intval($g_cgival["album_id"]);
	
	//上图
	cgi::get($g_cgival["img1"], "img1", "");
	$g_cgival["img1"] = string::un_script_code($g_cgival["img1"]);
	$g_cgival["img1"] = string::un_html($g_cgival["img1"]);
	
	//下图1
	cgi::get($g_cgival["img2"], "img2", "");
	$g_cgival["img2"] = string::un_script_code($g_cgival["img2"]);
	$g_cgival["img2"] = string::un_html($g_cgival["img2"]);
	
	//下图2
	cgi::get($g_cgival["img3"], "img3", "");
	$g_cgival["img3"] = string::un_script_code($g_cgival["img3"]);
	$g_cgival["img3"] = string::un_html($g_cgival["img3"]);
	
	//下图3
	cgi::get($g_cgival["img4"], "img4", "");
	$g_cgival["img4"] = string::un_script_code($g_cgival["img4"]);
	$g_cgival["img4"] = string::un_html($g_cgival["img4"]);

}

function get_data()
{
	global $g_cgival, $g_pro, $g_show;
	
	$admin_log = new admin_log();
	$db = new db_food_album();
	$status_db = new db_food_album_status();
	//$class_db = new db_food_album_class();	
	
	$site_id = admin::admin_get_user_site_id();	// 拿到当前站点的site_id
	$admin_id = admin::admin_get_login_uid();	// 拿到当前管理员ID
	$admin_name = admin::admin_get_login_user_name();	// 拿到当前管理员用户名
	
	
	// 获取当前专辑信息
	$check[0] = $g_cgival["album_id"];
	$album_info = $db->admin_get_food_album_by_ids($check);
	
	// 异常处理
	if(empty($album_info))
	{
		throw new Exception("该专辑不存在");
	}
	if($site_id != 900 && $album_info[0]["site_id"] != $site_id)
	{
		throw new Exception("您没有操作该专辑的权限");
	}

	// 更新专辑推荐图片
	$album_rec = $db->admin_update_food_album_tj_by_id($g_cgival["album_id"],1,$g_cgival["img1"],$g_cgival["img2"],$g_cgival["img3"],$g_cgival["img4"],$admin_id,$admin_name);
	if(!$album_rec)
	{
		throw new Exception("操作失败");
	}

	//add 审核专辑通过 by renxin1 6/11
	$db->admin_update_food_album_check_by_id(array($g_cgival["album_id"]),1,$admin_id,$admin_name);
	
	$admin_log->admin_insert_log_info($admin_id, $site_id, 3, "缩略图推荐 专辑album_id={$g_cgival["album_id"]}");
	
}

$g_show["error"] = 0;
$g_show["errmsg"] = '';

try
{
	admin_check_login();
// 	admin_check_user_priv("foodv2/album/ajax_album_thumb_rec.php");
	
	check_cgi_pro();
	get_data();
}
catch(Exception $e)
{
	$g_show["error"] = 1;
	$g_show["errmsg"] = $e->getMessage();
}

show_pro();
exit;


function show_pro()
{
	global $g_cgival, $g_pro, $g_show;
	if(isset($_GET['debug']))
		print_r($g_show);
	echo output::json('json',$g_show);
}

?>